<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<script type="text/javascript">
$(function(){
	$('#UserTimeData').datagrid({
		fit: true,
		nowrap: false,
		striped: true,
		singleSelect: true,
		url: '<c:url value="/usertime/findUsertime.do"/>',
		idField: 'id',
		frozenColumns:[[
           {field:'ck',checkbox:true}
   		]],
		columns: [[
            {field:'computerName',title:'计算机名',width:300},
			{field:'url',title:'地址',width:150},
			{field:'browseTime',title:'访问时长',width:100},
			{field:'rercent',title:'百分百',width:100},
			{field:'addUser',title:'添加人',width:100, formatter:function(value, rowData){
				return rowData.addUser != null ? rowData.addUser.name : '';
			}},
			{field:'addTime',title:'添加时间',width:100}
		]],
		toolbar:[{
			text: '导入',
			iconCls: 'icon-save',
			handler: inputUserTime
		}],
		pageSize: 20,
		pagination: true,
		rownumbers: true
	});
});

function inputUserTime(){
	$('#userTimeFile').dialog({
		title: '导入上网时长',
		modal: true,
		closable: true,
		draggable: true,
		width: 390,
		height: 120,
		toolbar: [{
			text:'保存',
			iconCls:'icon-save',
			handler: saveUserTimeFile
		},{
			text:'关闭',
			iconCls:'icon-cancel',
			handler: function() {
				$('#userTimeFile').dialog('close');
			}
		}] 
	}).dialog('open');
}

function saveUserTimeFile(){
	var filepath = document.getElementById("userFilePath");
	$('#timeMsg').show();
	if (filepath!=null){
		$.ajaxFileUpload({
			url: '<c:url value="/usertime/saveUserTime.do"/>',
			secureuri:false,
			fileElementId:'userFilePath',
			dataType: 'json',
			success: function (result){
				$('#userTimeFile').dialog('close').remove();
				if(result.success){
					$('#UserTimeData').datagrid('reload');
					$('#timeMsg').hide();
					$.messager.alert('提示', result.data , 'info');		
				}else{
					$.messager.alert('错误', result.data , 'info');
				}
			}
		});
	}
} 
</script>
<table id="UserTimeData"></table>
<div id="userTimeFile" class="easyui-dialog" style="padding: 5px;overflow: hidden;" closed="true">
	<div style="float:left;margin:1px 1px 0 0;"> 
	导入上网记录文件：<input id="userFilePath" type="file" name="userFilePath"  style="width:240px;"/>
	</div>
	<div id="timeMsg" style="text-align:center;display:none;"><font color=red>正在导入,请稍侯...</font>
	</div>
</div>
